﻿using FluentValidation;
using Sgr.UPMS.Application.Commands.UserProfile;
using Sgr.Utilities;

namespace Sgr.UPMS.Application.Validations.UserProfile
{
    /// <summary>
    /// 绑定邮箱地址命令验证器
    /// </summary>
    public class BindEmailCommandValidator : AbstractValidator<BindEmailCommand>
    {
        public BindEmailCommandValidator()
        {
            // 邮箱地址验证规则
            RuleFor(x => x.EmailAddress)
                .NotEmpty().WithMessage("邮箱地址不能为空")
                .MaximumLength(50).WithMessage("邮箱地址长度不能超过50个字符")
                .Must(email => RegexHelper.IsValidEmail(email)).WithMessage("请输入有效的电子邮箱地址");

            // 验证码验证
            RuleFor(command => command.VerificationCode)
                .NotEmpty()
                .WithMessage("验证码不能为空")
                .Length(6)
                .WithMessage("验证码必须是6位字符");

            // 用途
            RuleFor(command => command.VerificationPurpose)
                .NotEmpty()
                .WithMessage("用途不能为空")
                .Length(4)
                .WithMessage("用途必须是4位字符");
        }
    }
}